/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package bgu.ppm.gtm.base.str;

import bgu.ppm.gtm.base.MutableStrategy;
import bgu.sonar.util.collections.Pair;
import java.util.Iterator;

/**
 *
 * @author User
 */
public class IntArrayStrategy implements MutableStrategy {

    private int[] values;
    private int owningPlayer;

    public IntArrayStrategy(int numberOfVariables, int owningPlayer) {
        values = new int[numberOfVariables];
        this.owningPlayer = owningPlayer;
    }

    @Override
    public int getNumberOfVariables() {
        return values.length;
    }

    @Override
    public int get(int variable) {
        return values[variable];
    }

    @Override
    public Iterator<Pair<Integer, Integer>> iterator() {
        return new Iterator<Pair<Integer, Integer>>() {
            int i = 0;

            @Override
            public boolean hasNext() {
                return i < getNumberOfVariables();
            }

            @Override
            public Pair<Integer, Integer> next() {
                return new Pair<Integer, Integer>(i, get(i++));
            }

            @Override
            public void remove() {
                throw new UnsupportedOperationException("Not supported.");
            }
        };
    }

    @Override
    public void set(int var, int val) {
        values[var] = val;
    }

    @Override
    public int getOwningPlayer() {
        return owningPlayer;
    }
}
